<template>
  <div>
    <!--条件筛选-->
    <TopFilter :list="topFilterList" :cols="3" :labelWidth="110" :collapse="false" @filterChange="changeHandle" @onCollapse="collapseHandle"></TopFilter>
    <!-- 列筛选-->
    <FilterTable
      ref="table"
      columnsRef="lhmFactoryCarDailyDynamics"
      :columns="columns"
      :dataSource="dataSource"
      :isMemoryPagination="true"
      :isExportExcel="true"
      exportFileName="在厂车日动态.xlsx"
      :isSelectColumn="isSelectColumn"
      :onColumnsChange="columns => (this.columns = columns)"
      :onRowSelectChange="selectChangeHandle"
      :onSyncTableData="tableAllData"
    >
      <template slot="controls" slot-scope="props">
        <!-- <el-button size="small" type="primary" @click="saveHandle">打印</el-button> -->
      </template>
    </FilterTable>
    <BasePrint ref="print" :data="printList" template="factoryCarDailyDynamics" />
  </div>
</template>

<script>
import { dictionary } from '@/utils/dictMixin';
import moment from 'moment';
import { getFactoryCarDailyData } from '@/api/repair/queryStatistics/queryAccounts';
export default {
  name: 'LHMFactoryCarDailyDynamics',
  components: {},
  mixins: [dictionary],
  data() {
    return {
      topFilterList: this.createTopFilterList(),
      boolean: false,
      dataSource: [],
      printList: [],
      isSelectColumn: false,
      columns: this.createTableCheckColumns()
    };
  },
  mounted() {
    // 分页
    this.BaseTable = this.$refs.table.$refs.pageTable;
  },
  methods: {
    createTopFilterList() {
      return [
        {
          type: 'RANGE_DATE',
          label: '日期范围',
          fieldName: 'beginDate|endDate',
          placeholder: '选择日期',
          initialValue: [
            moment(new Date())
              .startOf('month')
              .format('YYYY-MM-DD'),
            moment(new Date()).format('YYYY-MM-DD')
          ],
          rules: [{ required: true, message: '请选日期范围', trigger: 'change' }]
          // rules: [{ required: true, month: true }]
        }
      ];
    },
    createTableCheckColumns() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '维修类别',
          dataIndex: 'REPAIR_TYPE_NAME',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'input'
        },
        {
          title: '车型',
          dataIndex: 'MODEL_NAME',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'input'
        },
        {
          title: '产量',
          dataIndex: 'CL',
          sorter: true,
          filter: true,
          summation: true,
          showOverflowTooltip: true,
          filterType: 'number'
        },
        {
          title: '在厂天数',
          dataIndex: 'ZCTS',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'number'
        },
        {
          title: '平均在场天数',
          dataIndex: 'PJZCTS',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'number'
        },
        {
          title: '当天出厂量',
          dataIndex: 'DTCC',
          sorter: true,
          filter: true,
          summation: true,
          showOverflowTooltip: true,
          filterType: 'number'
        },
        {
          title: '当天出厂量百分比',
          dataIndex: 'DTCLBFB',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'input'
        }
      ];
    },
    tableAllData(val) {},
    selectChangeHandle(val) {
      this.selectedRow = val;
    },
    async changeHandle(val) {
      this.dataSource = [];
      this.BaseTable.START_LOADING();
      // console.log('val', val);
      this.printList.beginDate = val.beginDate.slice(0, 10);
      this.printList.endDate = val.endDate.slice(0, 10);
      if (val.endDate) {
        val.beginDate = val.beginDate.slice(0, 10) + ' 00:00:00';
        val.endDate = val.endDate.slice(0, 10) + ' 23:59:59';
      }
      try {
        let res = await getFactoryCarDailyData(val);
        if (res.resultCode == 200) {
          this.dataSource = res.data;
        }
      } catch (error) {
      } finally {
        this.BaseTable.STOP_LOADING();
      }
    },
    collapseHandle() {
      this.$nextTick(() => {
        this.BaseTable.EXECUTE_RESET_HEIGHT();
      });
    },
    saveHandle() {
      this.$refs.print.EXCUTE_PRINT();
    }
  }
};
</script>
<style lang="less" scoped></style>
